<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Recharge;
class RechargeController extends Controller
{

    public function __construct()
    {
        view()->share([
            '_customers' => 'am-in',
            '_listRecharge' => 'am-active',

        ]);

    }
    //显示充值额度调整页面
    public function listRecharge(){
        $rechargeArr=Recharge::get();
        return view('admin.recharge.listRecharge',compact('rechargeArr'));
    }

    //修改充值面额
    public function updateRecharge($id){
        $rechargeInfo=Recharge::store($id);
        return view('admin.recharge.updateRecharge',compact('rechargeInfo'));
    }

    //新增充值面额
    public function addRecharge(){
        return view('admin.recharge.addRecharge');
    }


    //保存或新增充值面额
    public function addOrUpdateRecharge(Request $request){
            Recharge::addOrUpdate($request->id,$request->denomination,$request->preferential);
            return redirect('admin/listRecharge')->with('success', '操作成功');

    }

    //删除充值面额
    public function deleteRecharge($id){
        $status=Recharge::destroy($id);
        if($status){
            return redirect('admin/listRecharge')->with('success','删除成功');
        }

    }

}
